package com.baidu.tcpThreadDemo1;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(7777);

        while (true){
            //调用accept方法 阻塞监控是否有客户端链接 没有就会阻塞
            Socket socket = serverSocket.accept();

            //若通过阻塞说明有新的客户端链接了
            System.out.println(socket.getRemoteSocketAddress() + "创建了新链接!");

            //有则创建线程
            ServerConnectThread serverConnectThread = new ServerConnectThread(socket);

            //开启线程
            serverConnectThread.start();

        }
    }
}
